﻿using System.Collections.Generic;
using System.IO;

namespace SystemUpdatesCore.Files
{
    public class MacroConfigFile : FileSave
    {
        /// <summary>
        /// 扩展名
        /// </summary>
        public string FileExtension { get { return ".config"; } }

        /// <summary>
        /// 配置文件名
        /// </summary>
        /// <returns></returns>
        public string FileName { get { return "service"; } }

        /// <summary>
        /// 获取文件路径根据文件名
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        string GetPath(string fileName)
        {
            return Path.Combine(FilePath, fileName + FileExtension);
        }


        /// <summary>
        /// 读取指定的文件
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public async Task<List<MacroConfigModel>> Read()
        {
            return await Read(FileName);
        }

        /// <summary>
        /// 读取指定的文件
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public async Task<List<MacroConfigModel>> Read(string fileName)
        {
            var filePath = GetPath(fileName);
            if (!File.Exists(filePath))
            {
                return new List<MacroConfigModel>();
            }
            return await base.Read<List<MacroConfigModel>>(filePath);
        }


        /// <summary>
        /// 保存文件
        /// </summary>
        /// <param name="list"></param>
        /// <param name="fileName"></param>
        public async Task Write(List<MacroConfigModel> list)
        {
            await Write(list, FileName);
        }

        /// <summary>
        /// 保存文件
        /// </summary>
        /// <param name="list"></param>
        /// <param name="fileName"></param>
        public async Task Write(List<MacroConfigModel> list, string fileName)
        {
            var filePath = GetPath(fileName);

            await base.Write(list, filePath);
        }



    }
}
